//<<<+++OPENSOURCE
//<<<+++OPENSOURCE_LICENSE
//<<<+++OPENSOURCE_BEGIN LIC==FOXIT||LIC==GOOGLE

//<<<+++OPENSOURCE_MUST_BEGIN
#ifndef _FX_ARABIC_
#define _FX_ARABIC_
//<<<+++OPENSOURCE_MUST_END

#ifndef _FXM_OPENSOURCE_
//<<<+++OPENSOURCE_MUST_BEGIN LIC==FOXIT

//Classes defined in this header
class IFX_ArabicChar;
class IFX_BidiChar;

//*****************************************************************************
//* Arabic utils
//*****************************************************************************
#ifdef __cplusplus
extern "C"
{
#endif

typedef struct _FX_ARBFORMTABLE
{
	FX_WCHAR	wIsolated;
	FX_WCHAR	wFinal;
	FX_WCHAR	wInitial;
	FX_WCHAR	wMedial;
}FX_ARBFORMTABLE, * FX_LPARBFORMTABLE;
typedef FX_ARBFORMTABLE const * FX_LPCARBFORMTABLE;

typedef struct _FX_ARAALEF
{
	FX_WCHAR	wAlef;
	FX_WCHAR	wIsolated;
}FX_ARAALEF, * FX_LPARAALEF;
typedef FX_ARAALEF const * FX_LPCARAALEF;

typedef struct _FX_ARASHADDA
{
	FX_WCHAR	wShadda;
	FX_WCHAR	wIsolated;
}FX_ARASHADDA, * FX_LPARASHADDA;
typedef FX_ARASHADDA const * FX_LPCARASHADDA;

FX_LPCARBFORMTABLE FX_GetArabicFormTable(FX_WCHAR unicode);
FX_WCHAR FX_GetArabicFromAlefTable(FX_WCHAR alef);
FX_WCHAR FX_GetArabicFromShaddaTable(FX_WCHAR shadda);

#ifdef __cplusplus
};
#endif

//*****************************************************************************
//* Arabic character access
//*****************************************************************************
//enumeration for arabic character position
enum FX_ARBPOSITION
{
	FX_ARBPOSITION_Isolated = 0,
	FX_ARBPOSITION_Final,
	FX_ARBPOSITION_Initial,
	FX_ARBPOSITION_Medial,
};

class IFX_ArabicChar
{
public:
	static IFX_ArabicChar*		Create();

	virtual void				Release() = 0;

	virtual FX_BOOL				IsArabicChar(FX_WCHAR wch) const = 0;
	virtual FX_BOOL				IsArabicFormChar(FX_WCHAR wch) const = 0;

	virtual FX_WCHAR			GetFormChar(FX_WCHAR wch, FX_WCHAR prev = 0, FX_WCHAR next = 0) const = 0;
	virtual FX_WCHAR			GetFormChar(const CFX_Char *cur, const CFX_Char *prev, const CFX_Char *next) const = 0;
};

//*****************************************************************************
//* Bidi line
//*****************************************************************************
//Reorder a text line
void FX_BidiLine(CFX_WideString &wsText, FX_INT32 iBaseLevel = 0);
void FX_BidiLine(CFX_TxtCharArray &chars, FX_INT32 iCount, FX_INT32 iBaseLevel = 0);
void FX_BidiLine(CFX_RTFCharArray &chars, FX_INT32 iCount, FX_INT32 iBaseLevel = 0);

//<<<+++OPENSOURCE_MUST_END
#endif

//*****************************************************************************
//* Determine character bidirection
//*****************************************************************************
class IFX_BidiChar
{
public:
	//static method to create an instance
	static IFX_BidiChar*	Create();

	//Release the current object
	virtual void			Release() = 0;

	//Set policy, if bSeparateNeutral is TRUE, each neutral piece will be separated and returned directly.
	//If bSeparateNeutral is FALSE, each neutral piece will be combined to the current non-neutral piece.
	//The default value is TRUE.
	virtual void			SetPolicy(FX_BOOL bSeparateNeutral = TRUE) = 0;

	//Append a character, return TRUE if get a bidi piece
	virtual FX_BOOL			AppendChar(FX_WCHAR wch) = 0;
	//End of the last character, return TRUE if get a bidi piece
	virtual FX_BOOL			EndChar() = 0;
	//Get the info of the bidi piece, iStart is the starting index number, and iCount is the number of characters
	//Return values:
	//   0 if the bidi piece is neutral
	//   1 if the bidi piece is LTR
	//   2 if the bidi piece is RTL
	virtual FX_INT32		GetBidiInfo(FX_INT32 &iStart, FX_INT32 &iCount) = 0;

//<<<+++OPENSOURCE_BEGIN LIC==FOXIT
	virtual FX_INT32		GetCurBidi() const = 0;
//<<<+++OPENSOURCE_END

	//Reset the current status
	virtual void			Reset() = 0;
};

//<<<+++OPENSOURCE_MUST_BEGIN
#endif //_FX_ARABIC_
//<<<+++OPENSOURCE_MUST_END

//<<<+++OPENSOURCE_END
